package com.tqjc.execute.security.service.impl;

import com.tqjc.execute.security.service.CraneSteelPlateCacheService;
import com.tqjc.system.core.redis.TaskRedisApi;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @projectName: BaotouSteel
 * @className: CraneSteelPlateCacheServiceImpl
 * @author: Patienyon
 * @description: 天车钢板缓存服务实现
 * @date: 2023/6/14 11:29
 */

@Service
public class CraneSteelPlateCacheServiceImpl implements CraneSteelPlateCacheService {

    public static String STEEL_CACHE_PREFIX = "_steel_cache";

    @Resource
    TaskRedisApi taskRedisApi;

    @Override
    public void addSteelPlate(String craneType, String plateNumber) {
        taskRedisApi.lSet(craneType+"_"+STEEL_CACHE_PREFIX,plateNumber);
    }

    @Override
    public void resetSteelPlate(String craneType) {
        List<Object> plates = getSteelPlate(craneType);
        if(plates.size()>0) {
            taskRedisApi.del(craneType+"_"+STEEL_CACHE_PREFIX);
        }

    }

    @Override
    public List<Object> getSteelPlate(String craneType) {
        return taskRedisApi.lGet(craneType+"_"+STEEL_CACHE_PREFIX,0,-1);
    }
}
